package com.shuqi.model.bean;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import com.shuqi.bookcontent.BookContentRender;

/**
 * 书籍章节信息
 * 
 */
public class BookChapterInfo implements Serializable {
    private static final long serialVersionUID = 7288490904968886389L;
    /** 此段(章节)文字的开头在全文中的字节索引 */
    private int startIndex;
    /** 此段(章节)文字的结尾在全文中的字节索引 */
    private int endIndex;
    /** 文件的偏移索引 */
    private int offestIndex;
    /** 章节所在卷的vid */
    private String vid;
    /** 获取当前章节，返回的结果code */
    private String chapterType;
    /** 获取章节信息返回的提示语 */
    private String message;
    /** 章节内容 */
    private String chaptercontent;
    /** 当前章节内容的字节数组 */
    private byte[] chapterBytes;
    /* UMD */
    /** 章节内起始索引：等同于书签的params1 */
    private String percent1;
    /** 保存书签时当前阅读页面第一行第一个字对应的字节偏移量，从书签恢复阅读时需要使用该值计算如何排版 */
    private int bookmarkByteOffset;
    /** 作者 */
    private String author;
    /* EPUB */
    /** 章节路径 */
    private String chapterpath;
    /** 上一章,当前章cid,下一章 */
    private String cids = null;
    /** 上一章,当前章mode,下一章 (支付模式: 0免费章节; 1全本; 2按章;3全本免费章节;) */
    private String payModes;
    /** 上一章,当前章cid,下一章 (payMode=1全本价格,payMode=2章节价格(逻辑判断使用价格)) */
    private String discountPrice;
    /** 上一章,当前章cid,下一章 (字数) */
    private String wordCounts;
    /** 上一章,当前章cid,下一章(章节名称) */
    private String name;

    private List<BookContentLineInfo> mContentLines;

    private BookContentInfo mBookContentInfo;

    public BookChapterInfo(BookContentInfo info) {
        mBookContentInfo = info;
    }

    public List<BookContentLineInfo> getContentLines() {
        return mContentLines;
    }

    public void refreshContentLines(int lineIndex, int divideByte, BookContentRender render) {
        try {
            mContentLines =
                    render.getLineinfosByIndex(new ArrayList<BookContentLineInfo>(), chapterBytes,
                            false, startIndex, divideByte, mBookContentInfo.getEncoding(),
                            mBookContentInfo.getType());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }

    public String getChapterpath() {
        return chapterpath;
    }

    public void setChapterpath(String chapterpath) {
        this.chapterpath = chapterpath;
    }

    public int getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }

    public int getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }

    public void setChapterVid(String vid) {
        this.vid = vid;
    }

    public String getChapterVid() {
        return vid;
    }

    /**
     * 1则成功获取信息,其他失败
     * 
     * @param curChapterType
     */
    public void setChapterType(String curChapterType) {
        this.chapterType = curChapterType;
    }

    /**
     * 获取当前章节内容的字节数组
     * 
     * @return curChapterInfo
     */
    public byte[] getChapterBytes() {
        return chapterBytes;
    }

    /**
     * 设置当前章节内容的字节数组
     * 
     * @param
     */
    public void setChapterBytes(byte[] curChapterBytes) {
        this.chapterBytes = curChapterBytes;
    }

    /** 获取章节内容返回的消息 */
    public String getMessage() {
        return message;
    }

    /** 设置获取章节内容返回的消息 */
    public void setMessage(String message) {
        this.message = message;
    }

    public String getPercent1() {
        return percent1;
    }

    public void setPercent1(String percent1) {
        this.percent1 = percent1;
    }

    public int getBookmarkByteOffset() {
        return bookmarkByteOffset;
    }

    public void setBookmarkByteOffset(int offset) {
        this.bookmarkByteOffset = offset;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getChapterContent() {
        return chaptercontent;
    }

    public void setChaptercontent(String chaptercontent) {
        this.chaptercontent = chaptercontent;
    }

    public void setChapterCid(String cid) {
        cids = cid;
    }

    public String getChapterCid() {
        return cids;
    }

    public void setChapterPayMode(String payMode) {
        payModes = payMode;
    }

    public String getChapterPayMode() {
        return payModes;
    }

    public void setChapterPrice(String price) {
        discountPrice = price;
    }

    public String getChapterPrice() {
        return discountPrice;
    }

    public void setChapterWordCount(String wordCount) {
        wordCounts = wordCount;
    }

    public String getChapterWordCount() {
        return wordCounts;
    }

    /**
     * 获取当前章节名称
     * 
     * @return
     */
    public String getChapterName() {
        return name;
    }

    public void setChapterName(String chapterName) {
        this.name = chapterName;
    }

    /**
     * 返回 chapterType 的值
     * 
     * @return chapterType 1则成功获取信息,其他失败
     */

    public String getChapterType() {
        return chapterType;
    }
    
    public boolean isValid() {
        return mContentLines != null;
    }

    public int getOffestIndex() {
        return offestIndex;
    }

    public void setOffestIndex(int offestIndex) {
        this.offestIndex = offestIndex;
    }
}
